<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:a4j="http://richfaces.org/a4j" xmlns:a="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">

	<rich:spacer height="30" />
	<a4j:form>
		<a4j:status>
			<f:facet name="start">
				<h:graphicImage value="/img/spinner.gif" />
			</f:facet>
		</a4j:status>
		<rich:panel>
			<f:facet name="header">
				<h:outputText value="Browsing existing users" />
			</f:facet>
			<h:panelGrid columns="1" id="mainTable">
				<rich:dataTable rowKeyVar="rkv" value="#{usersManage.all}"
					var="user" onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
					rows="10"
					onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
					<rich:column id="loginCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="Login" />
						</f:facet>
						<h:outputText value="#{user.loginName}" />
					</rich:column>
					<rich:column id="passwordCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="Password" />
						</f:facet>
						<h:outputText value="#{user.password}" />
					</rich:column>
					<rich:column id="firstNameCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="First Name" />
						</f:facet>
						<h:outputText value="#{user.firstName}" />
					</rich:column>
					<rich:column id="surnameCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="Surname" />
						</f:facet>
						<h:outputText value="#{user.surname}" />
					</rich:column>
					<rich:column id="emailCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="E-mail" />
						</f:facet>
						<h:outputText value="#{user.email}" />
					</rich:column>
					<rich:column id="balanceCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="Balance" />
						</f:facet>
						<h:outputText value="#{user.balance}" />
					</rich:column>
					<rich:column id="birthDateCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="Birth Date" />
						</f:facet>
						<h:outputText value="#{user.birthDate}" />
					</rich:column>
					<rich:column id="registerDateCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="Register Date" />
						</f:facet>
						<h:outputText value="#{user.registerDate}" />
					</rich:column>
					<rich:column id="deleteActionCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="Delete" />
						</f:facet>
						<a4j:commandLink action="#{userDAO.getDAO().makeTransient(user)}"
							reRender="mainTable" value="Delete" />
					</rich:column>
					<rich:column id="blockActionsCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="(Un)Block" />
						</f:facet>
						<a4j:commandLink rendered="#{user.isBlocked == false}"
							action="#{usersManage.blockUser(user)}" reRender="mainTable"
							value="Block" />
						<a4j:commandLink rendered="#{user.isBlocked == true }"
							action="#{usersManage.unblockUser(user)}" reRender="mainTable"
							value="UnVlock" />
					</rich:column>
					<rich:column id="cancelActionsCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="(Un)Cancel" />
						</f:facet>
						<a4j:commandLink rendered="#{user.isCancelled == false}"
							action="#{usersManage.cancelUser(user)}" reRender="mainTable"
							value="Cancel" />
						<a4j:commandLink rendered="#{user.isCancelled == true }"
							action="#{usersManage.uncancelUser(user)}" reRender="mainTable"
							value="UnCancel" />
					</rich:column>
					<rich:column id="detailsCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="User's slips" />
						</f:facet>
						<a4j:commandLink action="#{usersManage.setDetails(user)}"
							reRender="detailsTable" value="Details" />
					</rich:column>
					<f:facet name="footer">
						<rich:datascroller align="center" />
					</f:facet>
				</rich:dataTable>
			</h:panelGrid>

			<h:panelGrid columns="1" id="detailsTable">
				<rich:dataTable rowKeyVar="rkv" width="400"
					value="#{usersManage.currentBettingSlips}" var="bettingSlip"
					rendered="#{usersManage.details != null}" rows="10"
					onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
					onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
					<rich:column id="betIdCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="ID" />
						</f:facet>
						<h:outputText value="#{bettingSlip.id}" />
					</rich:column>
					<rich:column id="moneyCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="Money" />
						</f:facet>
						<h:outputText value="#{bettingSlip.money}" />
					</rich:column>
					<rich:column id="quantityCol">
						<f:facet name="header">
							<h:outputText styleClass="headerText" value="# of bets" />
						</f:facet>
						<h:outputText
							value="#{betDAO.getDAO().getEntitiesCount(bettingSlip)}" />
					</rich:column>
					<f:facet name="footer">
						<rich:datascroller align="center" />
					</f:facet>
				</rich:dataTable>
			</h:panelGrid>
		</rich:panel>
	</a4j:form>

</ui:composition>